#include<bits/stdc++.h>
using namespace std;
struct Bag
{
	double n,v;
	bool operator < (const Bag &x) const
	{
		return v/n>x.v/x.n;
	}
}bag[1000];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		double w;
		int s;
		cin>>w>>s;
		for(int i=1;i<=s;i++)
			cin>>bag[i].n>>bag[i].v;
		sort(bag+1,bag+s+1);
		double totalV=0;
		for(int i=1;i<=s;i++)
		{
			if(w-bag[i].n>=0)
			{
				totalV+=bag[i].v;
				w-=bag[i].n;
			}
			else
			{
				totalV+=w/bag[i].n*bag[i].v;
				w=0;
			}
		}
		printf("%.2f\n",totalV);
	}
    return 0;
}
